package utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeUtils {
	public static Date parseDateTime(String toParse) {
		Date retval = null;
		
		try {
			SimpleDateFormat outFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
			retval = outFormat.parse(toParse);
		} catch (ParseException ex) {
			
		}
		
		if(retval == null) {
			try {
				SimpleDateFormat outFormat = new SimpleDateFormat("dd.MM.yy HH:mm");
				retval = outFormat.parse(toParse);
			} catch (ParseException ex) {
				
			}
		}
		
		if(retval == null)
			retval = parseDate(toParse);
		
		return retval;
	}
	
	public static Date parseDate(String toParse) {
		Date retval = null;
		
		try {
			SimpleDateFormat outFormat = new SimpleDateFormat("dd.MM.yyyy");
			retval = outFormat.parse(toParse);
		} catch (ParseException ex) {
			
		}
		
		if(retval == null) {
			try {
				SimpleDateFormat outFormat = new SimpleDateFormat("dd.MM.yy");
				retval = outFormat.parse(toParse);
			} catch (ParseException ex) {
				
			}
		}
		
		return retval;
	}
	
	public static Date parseTime(String toParse) {
		Date retval = null;
		
		try {
			SimpleDateFormat outFormat = new SimpleDateFormat("HH:mm");
			retval = outFormat.parse(toParse);
		} catch (ParseException ex) {
			
		}
		
		return retval;
	}
}
